class DownloadStatus {
  const DownloadStatus({
    required this.id,
    required this.title,
    required this.description,
    required this.uri,
    required this.totalSizeBytes,
    required this.localUri,
    required this.status,
    required this.bytesDownloadedSoFar,
  });

  factory DownloadStatus.fromJson(Map<dynamic, dynamic> json) {
    return DownloadStatus(
      id: json['id'] as int,
      title: json['title'] as String,
      description: json['description'] as String,
      uri: Uri.parse(json['uri'] as String),
      totalSizeBytes: json['totalSizeBytes'] as int,
      localUri: json['localUri'] != null
          ? Uri.parse(json['localUri'] as String)
          : null,
      status: json['status'] as int,
      bytesDownloadedSoFar: json['bytesDownloadedSoFar'] as int,
    );
  }

  static const int statusFailed = 16;
  static const int statusPaused = 4;
  static const int statusPending = 1;
  static const int statusRunning = 2;
  static const int statusSuccessful = 8;

  final int id;
  final String title;
  final String description;
  final Uri uri;
  final int totalSizeBytes;
  final Uri? localUri;
  final int status;
  final int bytesDownloadedSoFar;

  double get progress => bytesDownloadedSoFar / totalSizeBytes;
  bool get isDone => status == statusFailed || status == statusSuccessful;
  bool get isFailed => status == statusFailed;
  bool get isSucceed => status == statusSuccessful;
}
